package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.EmployeeBean;
import com.project.mapper.IEmployeeMapper;
import com.project.service.IEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;

@Service
@Transactional
public class EmployeeServiceImpl implements IEmployeeService {
    @Autowired
    private IEmployeeMapper mapper;

    @Override
    public IPage<EmployeeBean> findByItem(Integer pageNO, Integer startMoney, Integer endMoney, String position) {
        QueryWrapper<EmployeeBean> qw = new QueryWrapper<>();
        if (startMoney != null) {
            qw.ge("e_money", startMoney);
        }
        if (endMoney != null) {
            qw.le("e_money", endMoney);
        }
        if (position != null && position.length() != 0) {
            qw.like("e_position", position);
        }
        return mapper.selectPage(new Page<>(pageNO, 3), qw);
    }

    @Override
    public void add(EmployeeBean em) {
        mapper.insert(em);
    }

    @Override
    public void del(Integer id) {
        mapper.deleteById(id);
    }

    @Override
    public void update(Integer id, Integer money) {
       EmployeeBean em= mapper.selectById(id);
       em.setMoney(money);
       mapper.updateById(em);
    }

    @Override
    public EmployeeBean findById(Integer id) {
        return mapper.selectById(id);
    }
}
